package com.app.mingluxing.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.mingluxing.R;
import com.app.mingluxing.bean.BindChildList;
import com.app.mingluxing.utils.CommonUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Aaron on 2015/7/21.
 */
public class ChooseAdapter extends BaseAdapter {

    private Context ctx;

    private List<BindChildList.Data> peoples;

    public ChooseAdapter(Context ctx, List<BindChildList.Data> peoples) {
        this.ctx = ctx;
        this.peoples = peoples;
    }

    public void setData(List<BindChildList.Data> peoples) {
        this.peoples = peoples;
    }

    @Override
    public int getCount() {
        return peoples.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;

        if (convertView == null) {

            convertView = View.inflate(ctx, R.layout.item_baby, null);
            viewHolder = new ViewHolder();
            viewHolder.iv_receiver_pic = (ImageView) convertView.findViewById(R.id.iv_receiver_pic);
            viewHolder.iv_is_select = (ImageView) convertView.findViewById(R.id.iv_is_select);
            viewHolder.tv_receiver_name = (TextView) convertView.findViewById(R.id.tv_receiver_name);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

//        final ImageView tempIv = viewHolder.iv_is_select;
//        viewHolder.iv_is_select.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                tempIv.setSelected(!tempIv.isSelected());
//            }
//        });
//     LogUtil.e("TAG", "peoples==>" + peoples);
//
//        People people = peoples.get(position);
//
//        LogUtil.e("TAG", "peopel==>" + people);
//
//        Boolean s = people.isSelect;
//        LogUtil.e("TAG", "viewHolder.iv_is_select==>" + viewHolder.iv_is_select);
//        viewHolder.iv_is_select.setSelected(peoples.get(position).isSelect == 1);
        viewHolder.iv_is_select.setSelected(peoples.get(position).isSelect);

//        if (position==0) {
//            viewHolder.iv_is_select.setSelected(true);
//        }else {
//            viewHolder.iv_is_select.setSelected(false);
//        }

        viewHolder.tv_receiver_name.setText(CommonUtils.isNull(peoples.get(position).nickName) ? "" : peoples.get(position).nickName);
        if (!CommonUtils.isNull(peoples.get(position).picUrl)) {
            ImageLoader.getInstance().displayImage(peoples.get(position).picUrl, viewHolder.iv_receiver_pic);
        }

        return convertView;
    }

    private class ViewHolder {
        private ImageView iv_receiver_pic;
        private ImageView iv_is_select;
        private TextView tv_receiver_name;

    }

}
